<template>
  <div class="page">
    <el-form
      class="form"
      :label-position="labelPosition"
      label-width="80px"
      size="medium"
    >
      <el-form-item label="岗位名称">
        <el-input v-model="jobForm.name"></el-input>
      </el-form-item>
      <el-form-item label="岗位类型">
        <el-input v-model="jobForm.type"></el-input>
      </el-form-item>
      <el-form-item label="招聘人数">
        <el-input v-model="jobForm.count"></el-input>
      </el-form-item>
      <el-form-item label="工资">
        <el-input v-model="jobForm.salary"></el-input>
      </el-form-item>
      <el-form-item label="简介">
        <el-input
          v-model="jobForm.introduction"
          type="textarea"
          maxlength="250"
          show-word-limit
          :autosize="{ minRows: 2, maxRows: 4 }"
        >
        </el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="saveNewJob">保存</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { localData } from "@/util/local";
import { newJob } from "@/api/job";
export default {
  data() {
    return {
      labelPosition: "right",
      jobForm: {
        name: "",
        type: "",
        count: "",
        salary: "",
        introduction: "",
      },
      userInfo: {},
    };
  },
  created() {
    this.userInfo = localData("get", "userinfo");
  },
  methods: {
    saveNewJob() {
      if(!this.userInfo.company_id){
        this.$message({
            message: "请先完善企业信息",
            type: "warning",
          });
          setTimeout(()=>{
            this.$router.push({ path: '/companyinfo' });
          },1000)
          return
      }
      const param = { ...this.jobForm, company_id: this.userInfo.company_id };
      newJob(param)
        .then((res) => {
          if (res.code == 200) {
            this.$message({
              message: "新增成功，待管理员审核",
              type: "success",
            });
            this.$router.push({ path: "/companyjob" });
          }
        })
        .catch((err) => {
          this.$message({
            showClose: true,
            message: err.data,
            type: "warning",
          });
        });
    },
  },
};
</script>

<style scoped>
.page {
  min-height: 100vh;
}
.page .form {
  width: 400px;
  margin: 20px;
}
</style>